<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');
class Article extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

	public function index()
	{
		$cid = intval($this->uri->segment(3));

		if ($cid <= 0) {
			$rs = $this->db->get('article_class');
			$class = $rs->row_array();
		}
		else {
			$rs = $this->db->where('id', $cid)->get('article_class');
			$class = $rs->row_array();
		}

		if ($this->l == 'en') {
			$class['name'] = $class['en_name'];
		}

		if ($class['mod'] == 'page') {
			$d['text'] = $this->db->where('cid', $class['id'])->get('article')->row_array();

			if ($this->l == 'en') {
				$d['text']['content'] = $d['text']['en_content'];
			}

			$d['class'] = $class;
			$this->show(array('header', 'article_left', 'article', 'footer'), $d);
		}
		else {
			$d['list'] = $this->db->where('cid', $class['id'])->get('article')->result_array();

			if ($this->l == 'en') {
				foreach ($d['list'] as $k => $v) {
					$d['list'][$k]['title'] = $v['en_title'];
					$d['list'][$k]['short_title'] = $v['en_short_title'];
				}
			}

			$d['class'] = $class;
			$this->show(array('header', 'article_left', 'zixun', 'footer'), $d);
		}
	}

	public function info()
	{
		$id = intval($this->uri->segment(3));
		$d['text'] = $this->db->where('id', $id)->get('article')->row_array();

		if ($this->l == 'en') {
			$d['text']['title'] = $d['text']['en_title'];
			$d['text']['content'] = $d['text']['en_content'];
		}

		$class = $this->db->where('id', $d['text']['cid'])->get('article_class')->row_array();

		if ($this->l == 'en') {
			$class['name'] = $class['en_name'];
		}

		$d['class'] = $class;
		$this->show(array('header', 'article_left', 'zixun_view', 'footer'), $d);
	}
}

?>
